package com.qf.buybook.book.controller;

import com.qf.buybook.book.service.BooksService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author dongjl
 * @since 2022-08-18
 */
@RestController
@RequestMapping("/book")
public class BooksController {

    @Autowired
    BooksService booksService;


    @GetMapping("/buy/{id}")
    public String buyBook(@PathVariable("id") Integer id ){

        boolean result;

        synchronized (this){
            result = booksService.buyBook(id);
        }

        if (result){
            return "ok";
        }else {
            return "failed";
        }

    }

}
